package uilayer;

import java.util.InputMismatchException;
import java.util.Scanner;
import controllayer.*;

/**
 * Textbased UI which allows the user to gain access to the sales tracking.
 *
 *@author Benjamin Ørskov
 *@author Lasse Lambertsen
 *@author Ole Kirk
 *@author Søren Søgaard
 */
public class TrackingUI {

	// instance variables - object by the type iCtrl
	/** The tracking ctrl. */
	private TrackingController tCtrl;

	/** The instance. */
	private static TrackingUI instance;

	/**
	 * Constructor for TrackingUI.
	 */
	private TrackingUI() {
		// Initialize tCtrl
		tCtrl = new TrackingController();
	}

	/**
	 * Gets the single instance of TrackingUI.
	 *
	 * @return single instance of TrackingUI
	 */
	public static TrackingUI getInstance() {
		if (instance == null) {
			instance = new TrackingUI();
		}
		return instance;
	}

	/**
	 * Person menu.
	 */
	public void trackingMenu() {
		boolean exit = false;
		try {
			while (!exit) { // that is: while exit is false
				int choice = writeTrackingMenu();
				if (choice == 1) { // Salesmen sorted by revenue
					System.out.println(tCtrl.getSortedSalesmanArray());
				}
				// else if(choice == 2){ //find person
				// personFindMenu();
				//
				// }
				// else if(choice == 3){ //update person
				// personUpdateMenu();
				//
				// }
				// else if(choice == 4){
				// personRemoveMenu();
				// }

				else {
					exit = true;
				}// end else
			}// end while
		}// end try
		catch (InputMismatchException e) {
			// do something clever with the exception
			System.out.println("Du skal indtaste et tal!");
			trackingMenu();
		}
	}

	/**
	 * Display person menu.
	 *
	 * @return the int
	 */
	private int writeTrackingMenu() { // makes an object keyboard to read input
		// from the screen
		Scanner keyboard = new Scanner(System.in);
		System.out.println("*** Tracking menu ***");
		System.out.println(" (1) Vis alle sælgeres salg");
		// System.out.println(" (2) Find person");
		// System.out.println(" (3) Rediger person");
		System.out.println(" (2) Hovedmenu");
		System.out.print("\n Vælg: ");

		int choice = keyboard.nextInt();
		return choice;
	}
}